package initialize

import (
	"fmt"
	"github.com/liangchao/blogo/src/common/global"
	"gorm.io/driver/mysql"
	"gorm.io/gorm"
)

// InitMysqlDB 初始化 mysql db
func InitMysqlDB() {
	mysqlInfo := global.Settings.MysqlInfo

	dsn := fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?charset=utf8mb4&parseTime=True&loc=Local",
		mysqlInfo.Name, mysqlInfo.Password, mysqlInfo.Host,
		mysqlInfo.Port, mysqlInfo.DBName)

	db, err := gorm.Open(mysql.Open(dsn), &gorm.Config{})
	if err != nil {
		panic(err)
	}

	global.DB = db

}
